#include "ClientMessageHandler.h"

ClientMessageHandler::ClientMessageHandler() {
	pthread_mutex_init(&mutex, NULL);
	userProfileManager = UserProfileManager::getInstance();
}

void ClientMessageHandler::enqueue_message(Message& message) {
	messages_queue.push(message);
}

void ClientMessageHandler::proccess_messages() {
	pthread_mutex_lock(&mutex);

	while (!messages_queue.empty()) {
		Message msg = messages_queue.front();
		userProfileManager->updateUserProfile(msg.getUserId(),
				msg.getContentId(), msg.getRating());

		messages_queue.pop();
	}

	pthread_mutex_unlock(&mutex);
}

